from selenium.webdriver.common.by import By

from app_L3.Base.wework_app import WeWorkApp
from app_L3.Page.person_info import PersonInfo
from app_L3.Page.search_page import SearchPage


class EditMember(WeWorkApp):
    _SAVE = By.XPATH, "//*[@text='保存']"
    _CLEAR=By.XPATH, "//*[@text='姓名']/parent::*/child::*[3]"
    _NEW_NAME = By.XPATH, "//*[@text='姓名']/parent::*/child::*[3]"
    _DELMEMBER = By.XPATH, "//*[@text='删除成员']"
    _DEL=By.XPATH, "//*[@text='删除']"
    def click_del_btn(self):
        self.swipe_element(*self._DELMEMBER).click()
        # 点击删除
        self.find_and_click(*self._DEL)
        return SearchPage(self.driver)
    def update_member(self,new_name):
        # 点击清空姓名
        self.find_and_clear(*self._CLEAR)
        # 重新输入姓名
        self.find_and_send_keys(*self._NEW_NAME,new_name)
        # 随机选择性别
        self.choose_sex()
        # 点击保存按钮
        ctrl = self.wait_for_click(self.driver,*self._SAVE)
        if ctrl == True:
            self.find_and_click(*self._SAVE)
        return PersonInfo(self.driver)

